﻿/*
   Author: Tomer Paz
   BOGO.com
   2007
*/

// game 'main' program. simply init game object with game-server host name

package monopoly {
	import flash.system.Security;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.display.StageAlign;
    import flash.display.StageScaleMode;
	import monopoly.Game.*;
	
	//tmp test dialogs
	//import monopoly.GameController.Dialogs.Templates.*;
//	import flash.events.MouseEvent;
//	import fl.controls.Button;
//debug:
//    import monopoly.chat.ChatClient;

	/* the Main class */
	
	public class main extends Sprite 
		{
		private var _ClientVer:uint	    = 10001;	// this could remain hard-coded!
		private var _getUserInp:UserInput;
		
		public function main():void 
			{
			// we shall retrieve from FUI (FUI gets from Web server DB) server_name + WEB_Server_name + client_id + session_id + game_id + secret-Key parameters
			// currently implementation for debugging (without FUI) - we take interactively from user:
			 _getUserInp = new UserInput();
			 _getUserInp.addEventListener(Event.COMPLETE, onUserInput);
			 addChild(_getUserInp);
			}
	   private function onUserInput(ev:Event):void
	       {			
			GameArgs.myIPAddrs	= _getUserInp.get_myIPAddrs();
			GameArgs.ServerName	= _getUserInp.get_serverHost();
			GameArgs.WebServer	= _getUserInp.get_WebHost();
			GameArgs.ClientID	= _getUserInp.get_ClientId();
			GameArgs.GameID		= _getUserInp.get_GameId();
			GameArgs.SecretKey	= _getUserInp.get_mySecKey();
			
			var _Game:Game = new Game(_ClientVer, this);
			
			stage.align = StageAlign.TOP_LEFT;
	        stage.scaleMode = StageScaleMode.NO_SCALE;
			addChild(_Game);
			// currently allow access to this stage from everywhere:
			var URIstring:String = "http://" + GameArgs.WebServer + "/crossdomains.xml";
			Security.loadPolicyFile(URIstring);
			Security.allowDomain("*");

//			_Game.StartGame();
			
			}
			
		// tempo test for dialogs...
	/*
		private function onClickDone(e:MouseEvent):void
			{
			if (e.target as Button)
				{
				//var dlg:RadiosDialog = e.currentTarget as RadiosDialog;
			
				trace("Chosen option was: " + e.currentTarget.ChosenOption);
				e.currentTarget.remove( );
				removeChild(Sprite(e.currentTarget));
				}
			}
	*/
		}
}